﻿<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>开始考试</title>
<script src="js/ceishi.js"></script>
<script>
window.onload = beginle; 
</script>
</head>
<body>
<h1>HTML 测验</h1><hr> 

<p id="info" style="color:red;"></p>
<hr>
<form action="score.html" method="post" id="form1" target="_self">
<p id="timer" style="color:blue;"></p><hr>
<div id="kaoshi"></div>
<input type="submit" value="交卷" id="submit">
</form>
</body>

<script>
function answer(ev) {
   
    form1.removeEventListener('click', answer, false);
    var result = [];
    var radio = document.querySelectorAll('input[type=radio]');
    for (var i = 0; i < radio.length; i++) {
        radio[i].onchange = function (ev2) {

            var request = {key: '', value: ''};
            request.key = this.name;
            request.value = this.value;
                     
 
            for (var i = result.length - 1; i >= 0; i--) {              
                if(result[i].key == request.key){
                    
                    result.splice(i,1);
                }
            } 
            result.push(request); 
          
           

        }
    }

    var submit = document.getElementById("submit");
    submit.onclick = function(){
        sessionStorage.setItem("key", JSON.stringify(result));        
    }    
};


var form1 = document.getElementById("form1"); 

form1.addEventListener('click', answer, false);

</script>
</html>

<script type="text/javascript">

var maxtime = 25 * 60; 

      function CountDown() {

        if (maxtime >= 0) {
          minutes = Math.floor(maxtime / 60);
          seconds = Math.floor(maxtime % 60);
          msg = "计时开始，距离结束还有" + minutes + "分" + seconds + "秒";
          document.getElementById("timer").innerHTML = msg;          
            --maxtime;
        } else{
           var submit = document.getElementById("submit");
           submit.click();  
        
        }
      }

      CountDown();

      timer = setInterval("CountDown()", 1000);   
 </script>